package com.misty.api.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.misty.dao.domain.Users;
import org.springframework.stereotype.Component;

/**
 * @ClassName : EntityConverter
 * @Description :
 * @Author :
 * @Date: 2023-01-10 13:42
 */
@Component
public class UsersConverter implements Converter<Users> {
    @Override
    public Class<?> supportJavaTypeKey() {
        return Users.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public Users convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return (Users)cellData.getData();
    }

    @Override
    public WriteCellData<String> convertToExcelData(Users value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return new WriteCellData<>(value.getUsername());
    }
}
